﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Hangjing.Common;
using Hangjing.SQLServerDAL;
using Hangjing.Model;
using Hangjing.DBUtility;

/// <summary>
///未结算商家
/// </summary>
public partial class qy_54tss_Admin_Sale_shopnosettle : System.Web.UI.Page
{
    /// <summary>
    /// 商家条件
    /// </summary>
    private string SqlWhere
    {
        get
        {
            object o = ViewState["SqlWhere"];
            return (o == null) ? "" : Convert.ToString(o);
        }
        set
        {
            ViewState["SqlWhere"] = value;
        }
    }

    /// <summary>
    /// 订单条件
    /// </summary>
    private string orderWhere
    {
        get
        {
            object o = ViewState["orderWhere"];
            return (o == null) ? "" : Convert.ToString(o);
        }
        set
        {
            ViewState["orderWhere"] = value;
        }
    }

    /// <summary>
    /// 排序字段
    /// </summary>
    protected string ordersort
    {
        get
        {
            object o = ViewState["ordersort"];
            return (o == null) ? "TotalPrice" : Convert.ToString(o);
        }
        set
        {
            ViewState["ordersort"] = value;
        }
    }

    Deliver bll = new Deliver();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            SqlWhere = " 1=1 and delflag = 0  and PType = 1 ";
            SqlWhere = new RightsTool().getShopWhere(SqlWhere);
            orderWhere = "  1=1 and delflag = 0 and OrderStatus = 3 and settlecycle = 1 ";
            orderWhere = new RightsTool().getOrderWhere(orderWhere);

            WebUtility.SetDDLCity(ddlcity);
            WebUtility.BindList("id", "classname", SectionProxyData.GetEdelivergroupList(), ddlGpsIMEI);

            InitSqlwhere();
        }
    }

    /// <summary>
    /// 绑定指定的数据
    /// </summary>
    protected void BindData()
    {

        IList<TogoInfo> shops = new Points().getShopSettles(AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, SqlWhere, orderWhere, ordersort);
        if (shops.Count > 0)
        {
            this.AspNetPager1.RecordCount = shops[0].DataID;
        }

        this.rptsum.DataSource = shops;
        this.rptsum.DataBind();

        AlertScript.AjaxRegisterScript("init();", UpdatePanel1);
    }

    protected void btSearch_Click(object sender, EventArgs e)
    {
        InitSqlwhere();
        BindData();
    }


    /// <summary>
    /// 生成查询条件
    /// </summary>
    protected void InitSqlwhere()
    {
        SqlWhere = " 1=1 and delflag = 0  and PType = 1 ";
        SqlWhere = new RightsTool().getShopWhere(SqlWhere);
        orderWhere = "  1=1 and delflag = 0 and OrderStatus = 3 and settlecycle = 1 ";
        orderWhere = new RightsTool().getOrderWhere(orderWhere);
      
     
        if (tbshopname.Text != "")
        {
            SqlWhere += " and Name like '%" + Utils.RegEsc(WebUtility.InputText(this.tbshopname.Text.Trim())) + "%'  ";
        }

        if (ddlcity.SelectedValue != "0")
        {
            SqlWhere += " and cityid = " + ddlcity.SelectedValue + "";
        }
        if (ddlGpsIMEI.SelectedValue != "-1")
        {
            SqlWhere += " and IsCallCenter = " + ddlGpsIMEI.SelectedValue + "";
        }

        if (this.tb_Start.Text != "")
        {
            SqlWhere += " and  [intime] > '" + WebUtility.InputText(this.tb_Start.Text) + "' ";
        }
        if (this.tb_End.Text != "")
        {
            SqlWhere += " and intime < '" + WebUtility.InputText(this.tb_End.Text) + " 23:59:59'";
        }
        if (tbinuse.Text.Trim() != "")
        {
            SqlWhere += " and phead like '%" + WebUtility.InputText(tbinuse.Text) + "%'";

        }

    }


    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        BindData();
    }


}
